/******************************************************************************
 * * hal.h - implementation of different hardware devices interface
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/

#ifndef HAL_H_
#define HAL_H_

#include "../lvgl.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "../../board.h"

#ifndef _UI_TYPE_H_
typedef unsigned char        UINT8;
typedef char                 INT8;
typedef unsigned short       UINT16;
typedef short                INT16;
typedef unsigned int         UINT32;
typedef int                  INT32;
typedef unsigned char        BOOL;
typedef float                FLOAT;
typedef double               DOUBLE;
typedef unsigned long long   UINT64;
typedef long long            INT64;
typedef void                 VOID;
#endif

typedef UINT32   TASK_ID;
typedef void*  TIMER_ID;
typedef UINT32   SEMA_ID;
typedef VOID (*CB_FUNC)(void *para);
typedef VOID (*TASK_CB_FUNC)(lv_task_t *para);
typedef void (*AUDIO_RECORD_CB_FUNC)(MCI_EVNET_T event , MCI_INFO_T info_type, int32_t value);

/* hal RTC interface begin */
typedef struct hal_rtc_s
{
    INT32 tm_sec;                                                                 // seconds [0,59]
    INT32 tm_min;                                                                 // minutes [0,59]
    INT32 tm_hour;                                                                // hour [0,23]
    INT32 tm_mday;                                                                // day of month [1,31]
    INT32 tm_mon;                                                                 // month of year [1,12]
    INT32 tm_year;                                                                // since 1970
    INT32 tm_wday;                                                                // sunday = 0
} hal_rtc_t;

typedef struct {
    uint32_t data_size;
    const uint8_t * data;
    int type;
}lv_audio_dsc_t;

typedef struct {
    void * buffer;
    uint32_t len;
}lv_audio_msg_t;

#define LV_AUDIO_DECLARE(var_name) extern const lv_audio_dsc_t var_name;

/*AMRExtrator.cpp FT=7, duration=20ms, framsize = 32Bytes, duration=20ms  */
#define HAL_AMR_BUFSIZE_PER_SECOND 1600 /* (1000 * framsize/duration) */

// RTC device number.
typedef enum
{
    RTC_ALARM_1 = 1,
    RTC_ALARM_2
} RTC_ALARM_ID;

typedef void (*AlarmCallback)(void);                                            // Call back func for Alarm expired

/**
 * Get RTC time
 * param (out) time:  hal_rtc_t*
 * return  void
 */
extern VOID Hal_Rtc_Gettime(hal_rtc_t *time);

/**
 * Set RTC time
 * param (in) time:  hal_rtc_t*
 * return  void
 */
extern VOID Hal_Rtc_Settime(hal_rtc_t *time);

/**
 * Set alarm
 * param (in) id:  RTC_ALARM_ID
 * param (in) time:  hal_rtc_t*
 * param (in) CallBack: AlarmCallback
 * return  void
 */
extern VOID Hal_Rtc_Set_Alarm(RTC_ALARM_ID id, hal_rtc_t *time, AlarmCallback CallBack);

/**
 * get Alarm information
 * param (in) id: RTC_UART_ID
 * param (out) time: hal_rtc_t *
 * return  void
 */
extern VOID Hal_Rtc_Get_Alarm(RTC_ALARM_ID id, hal_rtc_t *time);                        // get alarm info

/**
 * start/stop alarm
 * param (in) id:  RTC_ALARM_ID
 * param (in) onoff: BOOL
 * return  void
 */
extern VOID Hal_Rtc_Enable_Alarm(RTC_ALARM_ID id, BOOL onoff);                          // start/stop alarm

/* HAL RTC interface end */

/* HAL battery interface begin */
// power info

/**
 * get battery status
 * param (in) void:
 * return battery remain percentage
 */
extern UINT8 Hal_Battery_Get_Status(VOID);

typedef struct battery_values_s{
    UINT32 battery_status;   // 0 - no battery; 1 - has battery
    UINT32 battery_val_mV;   // voltage
    UINT32 charge_cur_mA;    // current
    INT32 battery_temp;     // temperature, oC
}battery_values_t;

/**
 * get battery values
 * param (out) battery_values_t *
 * return void
 */
extern VOID Hal_Battery_Get_Values(battery_values_t *values);

/**
 * Register low power callback
 * param (in) cb: callback
 * return void
 */
extern VOID Hal_Register_Low_Power_Ind(CB_FUNC cb);

/* HAL battery interface end */

/* HAL charger interface begin */
typedef enum
{
    HAL_CHG_CONNECTED,                                                          // charger connected
    HAL_CHG_DISCONNECTED                                                        // charger disconnected
} HAL_CHG_STATUS;

/**
 * register charger status indication
 * param (in) func: CB_FUNC  call back function which is called when changer status change.
 * return  void
 */
extern VOID Hal_Register_Charger_Status_Ind(CB_FUNC cb);

/**
 * get charger status
 * param (in) void:
 * return  HAL_CHG_STATUS
 */
extern HAL_CHG_STATUS Hal_Charger_Get_Status(VOID);

/* HAL charger interface end */

/* HAL lcd interface begin */
/**
 * wake up lcd
 * param (in) void:
 * return  void
 */
extern VOID Hal_Lcd_Wakeup(VOID);

/**
 * make lcd go to sleep to save power
 * param (in) void:
 * return  void
 */
extern VOID Hal_Lcd_Sleep(VOID);
/* HAL lcd interface end */

/**
 * wake up touch
 * param (in) void:
 * return  void
 */
extern VOID Hal_Touch_Wakeup(VOID);

/**
 * make touch go to sleep to save power
 * param (in) void:
 * return  void
 */
extern VOID Hal_Touch_Sleep(VOID);

/**
 * wake up touch and LCD
 * param (in) void:
 * return  void
 */
extern VOID Hal_Lcd_Touch_Wakeup(VOID);

/**
 * make touch and LCD go to sleep to save power
 * param (in) void:
 * return  void
 */
extern VOID Hal_Lcd_Touch_Sleep(VOID);

/**
 * refresh lcd in ambient mode
 * param (in) void:
 * return  void
 */
VOID Hal_Lcd_idle_refresh(VOID);

/* HAL backlight interface begin */
// backlight intensity level
typedef enum
{
    HAL_INTENSITY_LEVEL_1,
    HAL_INTENSITY_LEVEL_2,
    HAL_INTENSITY_LEVEL_3,
    HAL_INTENSITY_LEVEL_4,
    HAL_INTENSITY_LEVEL_5
} HAL_INTENSITY_LEVEL;

/**
 * turn on backlight
 * param (in) void:
 * return  void
 */
extern VOID Hal_Backlight_On(VOID);

/**
 * turn off backlight
 * param (in) void:
 * return  void
 */
extern VOID Hal_Backlight_Off(VOID);

/**
 * set backlight intensity level
 * param (in) intensity:   HAL_INTENSITY_LEVEL
 * return  void
 */
extern VOID Hal_Backlight_Intensity_Set(HAL_INTENSITY_LEVEL intensity);

/**
 * set backlight intensity level
 * param (in) intensity:   int intensity
 * return  void
 */
extern VOID Hal_Backlight_Intensity_Set_For_Oledpanel(int intensity);

/**
 *get backlight status
 *param (in) void:
 *return UINT8: 0 off, 1 on
 */
extern UINT8 Hal_Get_Backlight_Status(VOID);

/* HAL backlight interface end */

/* HAL UART interface begin */
// UART device number.
typedef enum
{
    RTC_UART_1 = 1,
    RTC_UART_2
} HAL_UART_ID;

/* HAL UART interface end */

/* HAL vibrator interface begin */
/**
 * vibrate only one time
 * param (in) func: CB_FUNC  call back function which is called when play over.
 * param (in) para: UINT32  para of call back function
 * return  void
 */
extern VOID Hal_Vibrator_Play_Onetime(CB_FUNC func, UINT32 para);

/**
 * vibrate only one time
 * param (in) func: CB_FUNC  call back function which is called when play over.
 * param (in) para: void *  para of call back function
 * param (in) duration: UINT32  play duration, ms
 * return  void
 */
extern VOID Hal_Vibrator_Play_Onetime_With_Para(CB_FUNC func, void *para, UINT32 duration);

/**
 * keep vibrating
 * param (in) void:
 * return  void
 */
extern VOID Hal_Vibrator_Play_Repeat(VOID);

/**
 * stop vibrating
 * param (in) void:
 * return  void
 */
extern VOID Hal_Vibrator_Play_End(VOID);

/* HAL vibrator interface end */

/* HAL audio&tone interface begin */
// Speaker volume
typedef enum
{
    HAL_AUDIO_SPK_MUTE = 0,
    HAL_AUDIO_SPK_LEVEL_0 = HAL_AUDIO_SPK_MUTE,
    HAL_AUDIO_SPK_LEVEL_1,
    HAL_AUDIO_SPK_LEVEL_2,
    HAL_AUDIO_SPK_LEVEL_3,
    HAL_AUDIO_SPK_LEVEL_4,
    HAL_AUDIO_SPK_LEVEL_5,
    HAL_AUDIO_SPK_LEVEL_6,
    HAL_AUDIO_SPK_LEVEL_7,
    HAL_AUDIO_SPK_LEVEL_8,
    HAL_AUDIO_SPK_LEVEL_9,
    HAL_AUDIO_SPK_LEVEL_10,
    HAL_AUDIO_SPK_LEVEL_MAX = HAL_AUDIO_SPK_LEVEL_10
} HAL_SPEAKER_GAIN;

typedef enum
{
    HAL_CALL_SPK_OFF = 0,
    HAL_CALL_SPK_ON
} HAL_CALL_SPEAKER;

#define HAL_AUDIO_FORMAT_AMR   3
#define HAL_AUDIO_FORMAT_PCM8  7
#define HAL_AUDIO_FORMAT_PCM16 8

/**
 * play tone for one time
 * param (in) buffer:  UINT32*
 * param (in) len:  UINT32
 * param (in) volume:  HAL_SPEAKER_GAIN
 * param (in) func: CB_FUNC  call back function which is called when play over.
 * param (in) para: UINT32  para of call back function
 * return  void
 */
extern VOID Hal_Tone_Play_Onetime(UINT32 *buffer, UINT32 len, HAL_SPEAKER_GAIN volume, CB_FUNC func, void *para);

/**
 * play tone repeatedly
 * param (in) buffer:  UINT32*
 * param (in) len:  UINT32
 * param (in) volume:  HAL_SPEAKER_GAIN
 * return  void
 */
extern VOID Hal_Tone_Play_Repeat(UINT32 *buffer, UINT32 len, HAL_SPEAKER_GAIN volume);

extern VOID Hal_Media_Tone_Play_Onetime(UINT32 *buffer, UINT32 len, HAL_SPEAKER_GAIN volume, CB_FUNC func,  void *para);
extern VOID Hal_Media_Tone_Play_Repeat(UINT32 *buffer, UINT32 len, HAL_SPEAKER_GAIN volume);
/**
 * stop playing tone
 * param (in) void:
 * return  void
 */
extern VOID Hal_Tone_Play_End(VOID);
extern VOID Hal_File_Play_Onetime(const char *path, HAL_SPEAKER_GAIN volume, CB_FUNC func, void *para, int32_t PlayProgress);
extern VOID Hal_File_Audio_Seekto(int32_t seekMs);
extern VOID Hal_File_Play_End(VOID);
extern void Hal_File_Record_With_Format_Req(const char *path, AUDIO_RECORD_CB_FUNC func, uint8_t format);
extern void Hal_File_Record_Start_Req(const char *path, AUDIO_RECORD_CB_FUNC func);
extern UINT32 Hal_File_Record_Stop_Req(UINT32 *pFile_size);
extern VOID Hal_Record_Buffer_With_Format_Req( UINT8 *buffer, UINT32 bufsize, UINT32 maxDurationMs, AUDIO_RECORD_CB_FUNC func, uint8_t format);
extern VOID Hal_Record_Buffer_Start_Req( UINT8 *buffer, UINT32 bufsize, UINT32 maxDurationMs, AUDIO_RECORD_CB_FUNC func);
extern UINT32 Hal_Record_Buffer_Stop_Req(UINT32 *recSize, UINT32 *durationMs);
extern uint8_t Hal_File_Get_AudioDurationTime(const char *path, uint32_t *pDurationTime);
extern VOID Hal_NFFS_File_Play_Onetime(const char *path, HAL_SPEAKER_GAIN volume, CB_FUNC func, void *para);
extern VOID Hal_NFFS_File_Play_Repeat(const char *path, HAL_SPEAKER_GAIN volume);
extern VOID Hal_NFFS_File_Play_End(VOID);
extern VOID Hal_NFFS_File_Record_Start_Req(const char *path, AUDIO_RECORD_CB_FUNC func);
extern UINT32 Hal_NFFS_File_Record_Stop_Req(UINT32 *pFile_size);
extern VOID Hal_Audio_SetVolume(UINT16 volume);
extern VOID Hal_Audio_Pause(VOID);
extern VOID Hal_Audio_Resume(VOID);

typedef struct _htc_play_info_s
{
    INT32 PlayProgress;
    INT32 curPlayTimeMs;
} hal_play_info_t;

/**
 * get play information
 * param (out) hal_play_info_t* PlayInformation
 * return  void
 */
extern VOID Hal_Audio_Get_PlayInformation(hal_play_info_t* PlayInformation);

/**
 * call speaker control
 * param (in) callspeaker:  HAL_CALL_SPEAKER
 * param (in) volume:  HAL_SPEAKER_GAIN
 * return  void
 */
extern VOID Hal_Call_Speaker(HAL_CALL_SPEAKER callspeaker, HAL_SPEAKER_GAIN volume);

/**
 * call speaker control
 * param (in) status: HAL_VOICE_CALL_STATUS
 * return  void
 */

typedef enum{
    VOICE_CALL_END = 1,
    VOICE_CALL_START,
} HAL_VOICE_CALL_STATUS;

VOID Hal_Set_Voice_Call_Status(HAL_VOICE_CALL_STATUS status);

/* HAL audio&tone interface end */

/* HAL NVRAM interface begin */
/**
 * write to NVRAM
 * param (in) addr:  UINT32*
 * param (in) data:  UINT32*
 * param (in) len:   UINT32
 * return  UINT32: bytes have been writen
 */
extern UINT32 Hal_Nvram_Write(UINT8 *addr, UINT8 *data, UINT32 len);

/**
 * read data from NVRAM
 * param (in) addr:  UINT32*
 * param (out) data:  UINT32*
 * param (in) len:   UINT32
 * return  UINT32: bytes have been read
 */
extern UINT32 Hal_Nvram_Read(UINT8 *addr, UINT8 *data, UINT32 len);

/* HAL NVRAM interface end */

/* HAL OSA interface begin */
// memory
/**
 * alloc memory
 * param (in) size:   UINT32
 * return  UINT32*: memory address
 */
#define Hal_Mem_Alloc(size) lv_mem_alloc(size)

/**
 * free memory
 * param (in) addr: UINT32*
 * return  void
 */
#define Hal_Mem_Free(addr) lv_mem_free(addr)
/**
 * memeory set with check function
 * param (in) p: VOID* addr dest
 * param (in) d: INT8 data to set
 * param (in) size: UINT32 size to set
 * return  void
 */
#define Hal_Mem_Set memset

/**
 * memeory copy with check function
 * param (in) dest: VOID*
 * param (in) src: VOID*
 * param (in) size: UINT32
 * return  void
 */
#define Hal_Mem_Copy memcpy
/**
 * start to recode malloc info fot memory leak checking
 * param (in) addr: UINT32*
 * return  void
 */
// message

/**
 * send message to task 'id'
 * param (in) id: TASK_ID
 * param (in) message: VOID*
 * return  void
 */
extern VOID Hal_Send_Message(TASK_ID id, VOID *message);

/**
 * receive message from task 'id'
 * param (in) id: TASK_ID
 * param (in) IsBlock: BOOL true means block
 * return  VOID*
 */
extern VOID *Hal_Receive_Message(TASK_ID id, BOOL IsBlock);

/**
 * get messages count of task 'id'
 * param (in) id: TASK_ID
 * return  UINT32
 */
extern UINT32 Hal_Get_Message_Count(TASK_ID id);

typedef struct
{
    CB_FUNC cb;
    void *param;
    BOOL repeat;
    BOOL valid;
} hal_timer_param_t;

/**
 * create and start timer
 * param (in) timeout: UINT32 (ms)
 * param (in) callback: CB_FUNC*
 * param (in) para: callback param
 * param (in) repeat: BOOL
 * return  TIMER_ID
 */
extern TIMER_ID Hal_Timer_Start(UINT32 timeout, CB_FUNC callback, void *param, BOOL repeat);

/**
 * stop and delete timer
 * param (in) id: TIMER_ID
 * return  void
 */
extern VOID Hal_Timer_Stop(TIMER_ID id);

/**
 * create semaphore
 * param (in) id: SEMA_ID
 * param (in) InitCnt: UINT32 initial value of semaphone
 * return  SEMA_ID *
 */
extern SEMA_ID *Hal_Sema_Create(UINT32 InitVal);

/**
 * destroy semaphore
 * param (in) id: SEMA_ID*
 * return  void
 */
extern VOID Hal_Sema_Destroy(SEMA_ID *id);

/**
 * lock semaphore
 * param (in) id: SEMA_ID*
 * return  void
 */
extern VOID Hal_Sema_Lock(SEMA_ID *id);

/**
 * unlock semaphore
 * param (in) id: SEMA_ID*
 * return  void
 */
extern VOID Hal_Sema_Unlock(SEMA_ID *id);

/* HAL OSA interface end */

typedef enum
{
    HAL_TYPE_POWER_OFF = 0,
    HAL_TYPE_REBOOT,
    HAL_TYPE_FACTORY_RESET,
} HAL_POWER_OFF_TYPE;

/**
 * power off
 * param (in) type: HAL_POWER_OFF_TYPE
 * return  void
 */
extern VOID Hal_Power_Off(HAL_POWER_OFF_TYPE type);

typedef enum
{
    HAL_POWERUP_ONKEY,
    HAL_POWERUP_REBOOT,
    HAL_POWERUP_USB,
    HAL_POWERUP_RTC_ALARM,
    HAL_POWERUP_BAT,
    HAL_POWERUP_SILENT_RESET,
    HAL_POWERUP_PRODUCTION,
    HAL_POWERUP_UNKNOWN,
} HAL_POWERUP_REASON;

/**
 * Get power on reason
 * param (in) void
 * return  enum HAL_POWERUP_REASON
 */
extern HAL_POWERUP_REASON Hal_Powerup_Get_Reason(VOID);

typedef struct cam_start_preview_s {
    UINT8 sensor_id;
    UINT16 width;
    UINT16 height;
}cam_start_preview_t;

/**
 * Start camera preview
 * param (in) params
 * return  -1: fail  0: success
 */
int Hal_Camera_Start_Preview(cam_start_preview_t *params);

/**
 * Stop camera preveiw
 * param (in) sensor_id
 * return  -1: fail  0: success
 */
int Hal_Camera_Stop_Preview(UINT8 sensor_id);

/**
 * Fill camera preview buffer if exist
 * param (out) rgbBuf
 * return  0: no  1: yes
 */
int Hal_Camera_Preview(UINT8 *rgbBuf);

/*
 * Get camera preview buffer if exist
 * param (in) width, height
 * param (out) rgbBuf
 * return  0: no  1: yes
 * */
int Hal_Camera_Preview2(UINT8 *rgbBuf, int width, int height);

/*
 * Get camera preview YUV buffer size
 * param (out) width, height
 * return  0: no  1: yes
 * */
int Hal_Camera_Preview_Yuv_Size(int *width, int *height);

#define HAL_QRCODE_SCAN_FULL_SIZE_HOR_RES 640
#define HAL_QRCODE_SCAN_FULL_SIZE_VER_RES 480
/**
 * Fill camera preview buffer if exist
 * param (out) yuvBuf
 * return  0: no  1: yes
 */
int Hal_Camera_Preview_Qrcode_Scan(UINT8 *yuvBuf);

/**
 * Render yuv420 data to a shown buffer
 * return  0: failed  1: ok
 */
uint32_t Hal_Yuv420_Render(int32_t yuv_width,
                   int32_t yuv_height,
                   int32_t render_width,
                   int32_t render_height,
                   uint8_t *yuv_buf,
                   uint8_t *render_buf,
                   uint8_t semi);

typedef struct cam_capture_s {
    UINT16 width;        //in out
    UINT16 height;       //in out
    UINT32 jpeg_size;    //out
}cam_capture_t;

/**
 * Camera capture
 * param (in&out) params
 * file_handle (in) params
 * return  -1: fail  0: success
 */
int Hal_Camera_Capture(cam_capture_t *params, int file_handle);

/**
 * get camera on flag
 * param (in&out) void
 * return  1: camera on  0: camera off
 */
uint8_t Hal_Camera_Get_On_Flag(void);

/**
 * Start camera  full size steam
 * param (in) sensor_id
 * param (in) pRecordParam
 * param (in) format
 * return  -1: fail  0: success
 */
int Hal_Camera_Start_FullSizeStream(UINT8 sensor_id, CAM_RECORD_PARMETERS_STRUCT *pRecordParam, UINT32 format);

/**
 * Stop camera full size steam
 * param (in&out) void
 * return  -1: fail  0: success
 */
int Hal_Camera_Stop_FullSizeStream(void);


/**
 * pm suspend
 * param void
 * return:  resume flag
 */
uint32_t Hal_Pm_Suspend(VOID);

/**
 * pm resume
 * param void
 * return  void
 */
void Hal_Pm_Resume(VOID);

/**
 * pm wake up
 * param void
 * return  void
 */
void Hal_Pm_WakeUp(VOID);

/**
 * get PM state
 * param void
 * return  PM_ON/PM_SUSPEND
 */
int Hal_Pm_Get_State(VOID);

/**
 * get timer counter
 * param void
 * return  timer counter, can use CLOCK_TICKS_TO_MICRO_SEC_CLK_32KHZ to ms
 */
#define CLOCK_TICKS_TO_MICRO_SEC_CLK_32KHZ(x)  ((x)>(0xFFFFFFFF/15625)?((x/512)*15625+((x%512)*15625)/512):(((UINT32)(x)*15625)/512))
#define MICRO_SEC_TO_CLOCK_TICKS_CLK_32KHZ(x)  ((x)>(0xFFFFFFFF/512)?((x/15625)*512+((x%15625)*512)/15625):(((UINT32)(x)*512)/15625))
uint32_t Hal_Timer_Get_Counter(void);

/**
 * init hal module
 * param (in) void
 * return  void
 */
extern VOID Hal_Init(VOID);

/*
* delete all nvm
 * param (in) void
 * return  void
*/
extern void Hal_Nvm_Factory_reset(void);

/*
 * get platform version
 * param (in) void
 * return  uint8_t
*/
uint8_t * Hal_Get_Platform_Version(void);

#if LV_USE_USER_DATA_FREE
extern void hal_user_data_free(lv_obj_t *p);
#endif

/*
 * set audio path to BT if BT connected
 * return wether BT path is set
*/
BOOL Hal_Set_BT_Audio_Path(HAL_SPEAKER_GAIN volume);

/**
 * disconnect BT audio path of call
 * return  void
 */
BOOL Hal_Disconnect_BT_Audio_Path(VOID);

/**
 * switch to LSP path
 * return  void
 */
VOID Hal_Switch_Audio_Speaker(HAL_SPEAKER_GAIN volume);

// Audio Ctrl priority
typedef enum
{
    AUDIO_CTRL_PRIORITY_1 = 0,  //phone
    AUDIO_CTRL_PRIORITY_2,      //vedio call
    AUDIO_CTRL_PRIORITY_SEARCH, //search watch
    AUDIO_CTRL_PRIORITY_TIMER,  //timer
    AUDIO_CTRL_PRIORITY_3,      //alarm
    AUDIO_CTRL_PRIORITY_4,      //speech recog
    AUDIO_CTRL_PRIORITY_5,      //voice msg
    AUDIO_CTRL_PRIORITY_6,      //audio player
    AUDIO_CTRL_PRIORITY_7,      //setting volume tone
    AUDIO_CTRL_PRIORITY_8,      //message
    AUDIO_CTRL_PRIORITY_MAX,
    AUDIO_CTRL_PRIORITY_INVALID = 0xFF,
} AUDIO_CTRL_PRIORITY;

typedef VOID (*AudioCtrlback)(AUDIO_CTRL_PRIORITY priority);               // Call back func for inform priority

typedef struct {
    AudioCtrlback callbackfunc[AUDIO_CTRL_PRIORITY_MAX];
}hal_audio_management_t;

/**
 * Inform the audio management that app want to play audio ,
 * when to play audio,you should register the callback
 * function and priority to the audio management.
 * param (in) priority: the priority of register app
 *            Callback:inform the new play priority to app
 * return  current play priority
 */
AUDIO_CTRL_PRIORITY Hal_Audio_Manage_Start_Req(AUDIO_CTRL_PRIORITY priority,AudioCtrlback Callback);

/**
 * Inform the management that audio has been finished,
 * when the audio has been finished,you should inform
 * the audio management that the priority which has been
 * finished.
 * param (in) priority: the priority of register app
 * return  VOID
 */
VOID Hal_Audio_Manage_End_Ind(AUDIO_CTRL_PRIORITY priority);

/**
 * Init audio management ctrl module
 * param (in) VOID
 * return  VOID
 */
VOID Hal_Audio_Manage_Init(VOID);

int HAL_sd_user_set(int val);
int HAL_sd_user_get(void);

enum
{
    AMBIENT_OFF = 0,
    AMBIENT_ON  = 1,
};
typedef uint8_t watch_ambient_type_t;
VOID Hal_ambient_flag_set(watch_ambient_type_t flag);
watch_ambient_type_t Hal_ambient_flag_get(void);

/* HAL usb connect interface begin */
typedef enum
{
    HAL_USB_CONNECTED,                                                          // usb connected
    HAL_USB_DISCONNECTED                                                        // usb disconnected
} HAL_USB_STATUS;

/* HAL usb connect interface begin */
/**
 * get usb connect status
 * param (in) void:
 * return  HAL_USB_STATUS
 */
HAL_USB_STATUS Hal_Get_Usb_Status(VOID);
/* HAL usb connect interface end */
BOOL Hal_Get_Sd_Ready(VOID);
BOOL Hal_Get_Sd_Fat_Ok(VOID);
BOOL Hal_Connect_To_Pc(VOID);

#ifdef LV_MEM_USER_DEBUG
void Hal_Mem_Alloc_Record(uint32_t size, void * addr, const char * func);
void Hal_Mem_Free_Record(const void * addr);
void Hal_Mem_Record_Dump(bool detail);
#endif

/**only for craneg A1**/
#ifdef USE_VAD
int Hal_Voice_Wakeup_Vad_On(void);
int Hal_Voice_Wakeup_Vad_Off(void);
int Hal_Voice_Wakeup_Vad_Get_Status(void);
#endif

#define SD_MOUNTED_AS_U_STORAGE -1
#define SD_REQUEST_UNMOUNT_FROM_U_STORAGE -2
#define SD_REMOUNT_OK 0

#ifdef __cplusplus
}
#endif

#endif
